﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Log;

namespace Core.Exception
{
    [Serializable]
    public class GeoException : System.Exception
    {
        protected virtual int ErrorCodePrefix { get { return 0x00; } }

        public int ErrorCode { get; private set; }

        public GeoException()
        { }

        public GeoException(int errorCode, string message)
            : base(message)
        {
            ErrorCode = (ErrorCodePrefix << 24) | errorCode;
            Log();
        }

        public GeoException(int errorCode, string message, System.Exception inner)
            : base(message, inner)
        {
            ErrorCode = errorCode;
            Log();
        }

        protected GeoException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            : base(info, context)
        { }

        protected virtual void Log()
        {
            BasicLog bl;
            if (this.InnerException!=null)
                bl = new BasicLog(LogPriority.ERROR, "0x" + this.ErrorCode.ToString("X8") + "\t\t" + this.Message + "\t\t" + this.InnerException.ToString());
            else
                bl = new BasicLog(LogPriority.ERROR, "0x" + this.ErrorCode.ToString("X8") + "\t\t" + this.Message);
            Logger.GetInstance().Add(bl);
        }
    }
}
